﻿package plugin.instances.game
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.instances.ui.*;
    import view.mornExtends.*;

    public class ShiWangDianGame extends HsdtUI implements IInstance
    {
        private var nextFreshTime:int = 0;
        private var time:int = 0;
        private var _instance:Object;
        private var _getters:Array;

        public function ShiWangDianGame()
        {
            this._getters = [];
            label_name1.addEventListener(MouseEvent.CLICK, this.name1ClickHandler);
            label_name.addEventListener(MouseEvent.CLICK, this.nameClickHandler);
            this.updateChishu();
            return;
        }// end function

        protected function name1ClickHandler(event:MouseEvent) : void
        {
            if (this._getters[1])
            {
                ModelProxy.change("zone", "autoMove", {x:this._getters[1].gameObj.baseObj.x, y:this._getters[1].gameObj.baseObj.y, stageid:this._getters[1].gameObj.baseObj.stageid});
            }
            return;
        }// end function

        protected function nameClickHandler(event:MouseEvent) : void
        {
            if (this._getters[0])
            {
                ModelProxy.change("zone", "autoMove", {x:this._getters[0].gameObj.baseObj.x, y:this._getters[0].gameObj.baseObj.y, stageid:this._getters[0].gameObj.baseObj.stageid});
            }
            return;
        }// end function

        private function itemRendler(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1.getChildByName("item") as FlashItem).data = param1.dataSource;
            }
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list.array = _loc_3[0];
            list.renderHandler = new Handler(this.itemRendler);
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            this._instance = param1;
            this.showItem(param1.show);
            shuoming.toolTip = param1.tips.replace(/#""#/g, "\n");
            var _loc_3:* = param2[InstancesPublic.INITSHIWANGDIAN];
            if (_loc_3 == null)
            {
                return;
            }
            this.time = 0;
            txt_time.visible = false;
            label_num.text = _loc_3.wave;
            label_num1.text = _loc_3.trueCorpseCount;
            if (_loc_3.hasOwnProperty("nextFreshTime"))
            {
                this.nextFreshTime = _loc_3.nextFreshTime;
                _loc_4 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                if (this.nextFreshTime - _loc_4 >= 0)
                {
                    label_times.width = 200;
                    label_times.text = TimeDataFormatUtil.getLeftTimeStr3(this.nextFreshTime - _loc_4);
                }
                _loc_5 = this.nextFreshTime - _loc_4;
                if (_loc_5 < 0)
                {
                    _loc_5 = 0;
                }
                if (_loc_5 <= 30)
                {
                    ModelProxy.change("mainui", "counter", {type:6, value:_loc_5});
                }
            }
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            switch(param1)
            {
                case InstancesPublic.TIMECHECKER:
                {
                    _loc_5 = int(param2);
                    txt_time.text = TimeDataFormatUtil.getLeftTimeStr3(_loc_5);
                    txt_time.visible = true;
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 >= 0)
                    {
                        label_times.text = TimeDataFormatUtil.getLeftTimeStr3(this.nextFreshTime - _loc_3);
                    }
                    if (_loc_4 == 30)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    break;
                }
                case InstancesPublic.INITSHIWANGDIAN:
                {
                    label_num.text = param2.wave;
                    this.nextFreshTime = param2.nextFreshTime;
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 < 0)
                    {
                        _loc_4 = 0;
                    }
                    if (this.nextFreshTime - _loc_3 >= 0)
                    {
                        label_times.width = 200;
                        label_times.text = TimeDataFormatUtil.getLeftTimeStr3(this.nextFreshTime - _loc_3);
                    }
                    if (_loc_4 <= 30)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    label_num1.text = param2.trueCorpseCount;
                    if (param2.trueCorpseCount == 0)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    break;
                }
                case InstancesPublic.SHIWANGDIANCHIYOUZHE:
                {
                    this._getters = param2 as Array;
                    this.updateChishu();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function updateChishu() : void
        {
            this._getters = ModelProxy.getValue("mainuiInstance", "swdchishizhe");
            if (this._getters[0])
            {
                label_name.text = this._getters[0];
            }
            else
            {
                label_name.text = "--";
            }
            if (this._getters[1])
            {
                label_name1.text = this._getters[1];
            }
            else
            {
                label_name1.text = "--";
            }
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            return;
        }// end function

        public function initEvent() : void
        {
            btn_tuichu.clickHandler = new Handler(this.doQuit);
            return;
        }// end function

        private function doQuit() : void
        {
            ModelProxy.change("zone", "exitInstance", null);
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
